<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>登录</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
    <link rel="icon" href="img/logo2.png" type="image/x-icon" />
    <link rel="stylesheet" href="css/common.css" />
    <link rel="stylesheet" href="css/logIn.css" />
    <script src="js/url_handler.js"></script>
  </head>
  <body>
    <div class="navigation">
      <!-- 头像 -->
      <img src="img/logo2.png" alt="未登录" />
      <div class="title">未登录</div>
      <div class="space"></div>
      <a href="blog_lists.html">主页</a>
    </div>
    <!-- 登录页面 -->

    <div class="login-Container">
      <div class="dialog">
        <h3>登录</h3>

        <div id="fileImage">
          <div>
            <input id="i" type="button" value="" />
          </div>
        </div>

        <div class="row" style="margin-top: 30px">
          <label for="username">用户名</label>
          <input type="text" id="username" />
        </div>
        <div class="row">
          <label for="password">密码</label>
          <input type="password" id="password" />
        </div>
        <div class="r" style="margin-top: 25px">
          <input
            type="button"
            id="goreg"
            value="注册"
            onclick="location.href = 'blog_register.html'"
          />
          <input type="button" id="submit" value="登录" onclick="login()" />
        </div>
      </div>
    </div>

    <script>
      jQuery("#i").css("background-image", "url()");
      jQuery("#username").val(getParamValue("username"));
      jQuery("#username").focus();
      jQuery("#username").blur(function () {
        var username = jQuery("#username");
        if (username.val().trim() != "") {
          jQuery("#i").css("background-image", "url(img/avatar.png)");
        } else {
          jQuery("#i").css("background-image", "url()");
        }
      });
      function login() {
        var username = jQuery("#username");
        var password = jQuery("#password");
        // 1. 非空校验
        if (username.val().trim() == "") {
          alert("请输入用户名！");
          username.focus();
          return false;
        }
        if (password.val().trim() == "") {
          alert("请输入密码！");
          password.focus();
          return false;
        }
        // 2. 发送请求
        location.href = "blog_lists.html";
      }
    </script>
  </body>
</html>
